<style xmlns="http://www.w3.org/1999/html">
    .layui-form-label.required:before { /* 这种写法也可以*/
        content: ' *';
        color: red;
    }
    .open-form .layui-input-block{
        margin-left: 145px;
    }
    .open-form .layui-form-label {
        width: 115px;
    }
</style>

<script type="text/javascript" src="../../../admin/assets/js/pdfobject.min.js"></script>
<!-- 表单弹窗 -->
<form lay-filter="productOrderForm" class="layui-form open-form">
    <div class="open-model">
        <div class="open-auto" style="padding-left: 5px;">
            <div class="examineProductionPlanForm-title">
                <h3 class="title" style="margin-top: 0;">提货订单信息</h3>
            </div>
            <div class="layui-form-item layui-row">
                <div class="layui-col-md4">
                    <label class="layui-form-label required">提货订单编号：</label>
                    <div class="layui-input-block">
                        <select id="orderNoInfo"  lay-search="" name="orderNoInfo" lay-filter="orderNoInfo"
                                class="common-select-search">
                        </select>
                    </div>
                </div>
                <div class="layui-col-md4 required">
                    <label class="layui-form-label">订单类型：</label>
                    <div class="layui-input-block">
                        <select id="orderType" disabled name="orderType" class="common-select-search"
                                lay-verify="required">
                        </select>
                    </div>
                </div>
                <div class="layui-col-md4">
                    <label class="layui-form-label required">所属客户：</label>
                    <div class="layui-input-block">
                        <select id="customerInfo" disabled name="customerInfo" lay-filter="customerInfo"
                                class="common-select-search">
                        </select>
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-row">
                <div class="layui-col-md4">
                    <label class="layui-form-label required">采购客户代码：</label>
                    <div class="layui-input-block">
                        <input id="purchaseCode" disabled name="purchaseCode" placeholder="采购客户代码" type="text" class="layui-input"
                               lay-verify="required"
                               required autocomplete="off"/>
                    </div>
                </div>
                <div class="layui-col-md4">
                    <label class="layui-form-label required">订单下单时间：</label>
                    <div class="layui-input-block">
                        <input id="orderTime" disabled name="orderTime" placeholder="订单下单时间" type="text" class="layui-input"
                               required autocomplete="off"/>
                    </div>
                </div>
            </div>
            <div class="examineProductionPlanForm-title">
                <h3 class="title">关联物料信息</h3>
            </div>
            <div class="layui-form-item layui-row">
                <div class="layui-col-md4">
                    <label class="layui-form-label required">产品类别：</label>
                    <div class="layui-input-block">
                        <div id="productTypeName" lay-filter="productTypeName">
                        </div>
                        <input id="productTypeId" name="productTypeId" type="hidden">
                    </div>
                </div>
                <div class="layui-col-md4">
                    <label class="layui-form-label required">内部SKU号：</label>
                    <div class="layui-input-block" id="SkuInfo">
                        <select id="inSkuCodeHave" name="inSkuCodeHave" lay-filter="inSkuCodeHave"
                                class="common-select-search">
                        </select>
                    </div>
                </div>
                <div class="layui-col-md4">
                    <label class="layui-form-label required">产品属性：</label>
                    <div class="layui-input-block">
                        <select id="assemblyNature" disabled name="assemblyNature" lay-filter="assemblyNature"
                                class="common-select-search">
                        </select>
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-row">
                <div class="layui-col-md4">
                    <label class="layui-form-label required">内部SKU名称：</label>
                    <div class="layui-input-block">
                        <input type="text" disabled id="inSkuName" name="inSkuName" class="layui-input"
                               placeholder="请输入名称">
                    </div>
                </div>
                <div class="layui-col-md4">
                    <label class="layui-form-label required">内部规格码：</label>
                    <div class="layui-input-block">
                        <input type="text" id="inSkuSpec" disabled name="inSkuSpec" class="layui-input"
                               placeholder="请输入名称">
                    </div>
                </div>
                <div class="layui-col-md4">
                    <label class="layui-form-label required">基础单位：</label>
                    <div class="layui-input-block">
                        <input type="text" disabled id="inUnit" name="inUnit" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="examineProductionPlanForm-title">
                <h3 class="title">提货明细信息</h3>
            </div>
            <div class="layui-form-item layui-row">
                <div class="layui-col-md4">
                    <label class="layui-form-label required">添加性质：</label>
                    <div class="layui-input-block">
                        <select id="deliveryNature" name="deliveryNature" disabled class="common-select-search"
                                lay-verify="required"/>
                    </div>
                </div>
                <div class="layui-col-md4">
                    <label class="layui-form-label required">生产线：</label>
                    <div class="layui-input-block">
                        <input type="text" id="productionLine" placeholder="请输入生产线名称" name="productionLine" class="layui-input">
                    </div>
                </div>
                <div class="layui-col-md4">
                    <label class="layui-form-label required">单位：</label>
                    <div class="layui-input-block">
                        <input type="text"  id="unitName" placeholder="请输入单位名称" name="unitName" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-row">
                <div class="layui-col-md4">
                    <label class="layui-form-label required">提货时间：</label>
                    <div class="layui-input-block">
                        <input type="text"  id="deliveryTime" placeholder="选择提货时间" name="deliveryTime" class="layui-input">
                    </div>
                </div>
                <div class="layui-col-md4">
                    <label class="layui-form-label required">提货数：</label>
                    <div class="layui-input-block">
                        <input type="text"  id="deliveryNum" placeholder="提货数" name="deliveryNum" class="layui-input">
                    </div>
                </div>
                <div class="layui-col-md4">
                    <label class="layui-form-label required">状态：</label>
                    <div class="layui-input-block">
                        <select id="status" name="status" lay-filter="status"
                                class="common-select-search">
                        </select>
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-row">
                <div class="layui-col-md4">
                    <label class="layui-form-label required">组件描述：</label>
                    <div class="layui-input-block">
                        <input type="text"  id="remark" placeholder="提货数" name="remark" class="layui-input">
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-filter="productOrderInfoFormSubmit" lay-submit>提交</button>
        </div>
    </div>
</form>

<!-- js部分 -->
<script>
    layui.use(['layer', 'form', 'table', 'laydate', 'admin', 'config'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var table = layui.table;
        var config = layui.config;
        var admin = layui.admin;
        var form = layui.form;
        var laydate = layui.laydate;


        let oldSkuInfo = new Map();
        let selectOrderInfo = new Map();

        laydate.render({
            elem: '#orderTime'
            , type: 'datetime'
        });


        laydate.render({
            elem: '#deliveryTime'
            , type: 'date'
        });

        //状态
        admin.getDictList("status", "pro_product_order_status", null, "状态");

        //提货订单 初始化
        admin.initDataSelectAndMap("production/delivery/admin/orderInfo/list", {limit: 9999}, "orderNoInfo", null, "提货订单", "orderNo", "id", selectOrderInfo);
        //物料类型
        admin.initDataSelectTree(true, 'enterprise/product/admin/productType/getAllTreeData', {materialNatureList: [2, 3, 7]}, 'productTypeName', null, "产品类别", "productTypeId", function (data) {
            let productTypeId = data.change[0].value;
            //清空
            $('#inUnit').val("");
            $('#inSkuName').val();
            //规格
            $('#inSkuSpec').val();
            //计量单位
            $('#inSkuUnit').val();
            //产品属性
            $('#assemblyNature').empty();
            //清空下拉
            $('#inSkuCodeHave').empty();
            admin.initDataSelectAndMap("enterprise/product/admin/productDetailWMS/list", {categoryType: "production",productTypeId:productTypeId}, "inSkuCodeHave", null, "SKU物料", "codeAndName", null, oldSkuInfo);

            //基础单位
            admin.reqSync('enterprise/product/admin/productUnit/getIsBaseUnitProductUnitByType', {
                type: 0,
                productTypeId: productTypeId
            }, res => {
                if (res.code === 200) {
                    if (res.data != null) {
                        let infoName = res.data.name || '';
                        $('#inUnit').val(infoName);
                    }
                }
            }, 'get');
        });

        //添加性质
        admin.getDictList("deliveryNature", "pro_product_order_source", "1", "添加性质");


        //产品属性
        admin.getDictList("assemblyNature", "product_assembly_nature", null, "产品属性");

        //sku号
        form.on('select(inSkuCodeHave)', function (data) {
            let val = data.value;
            let skuInfo = {};
            if (oldSkuInfo.get(val)) {
                skuInfo = oldSkuInfo.get(val);
                //回显
                //sku名称
                $('#inSkuName').val(skuInfo.skuName);
                //规格
                $('#inSkuSpec').val(skuInfo.skuSpec);
                //计量单位
                $('#inSkuUnit').val(skuInfo.unitId);
                //产品属性
                $('#assemblyNature').val(skuInfo.assemblyNature);

                admin.reqSync('enterprise/product/admin/productUnit/getIsBaseUnitProductUnitByType', {
                    type: 0,
                    productTypeId: skuInfo.productTypeId
                }, res => {
                    if (res.code === 200) {
                        if (res.data != null) {
                            let infoName = res.data.name || '';
                            $('#inUnit').val(infoName);
                        } else {
                            $('#inUnit').val("");
                        }
                    }
                }, 'get');
                //说明
                $('#inRemark').val(skuInfo.remark);
                form.render("select")
            }
        });

        admin.initDataSelectAndMap("enterprise/product/admin/productDetailWMS/list", {categoryType: "production"}, "inSkuCodeHave", null, "SKU物料", "codeAndName", null, oldSkuInfo);

        form.on('select(orderNoInfo)', function (data) {
            let val = data.value;
            if (val) {
                let orderInfo = selectOrderInfo.get(val);
                $("#orderTime").val(orderInfo.orderTime)
                $("#purchaseNameInfo").val(orderInfo.purchaseName)
                $("#purchaseCode").val(orderInfo.purchaseCode)
                $("#orderType").val(orderInfo.orderType)
                $("#orderNo").val(orderInfo.orderNo)
                //订单类型
                admin.getDictList("orderType", "pro_product_order_type", orderInfo.orderType, "订单类型");

                admin.req('enterprise/sell/admin/customersInfo/list', {limit: 9999}, function (res) {
                    if (res.code == 200) {
                        if (res.data.length > 0) {
                            $.each(res.data, function (index, item) {
                                $('#customerInfo').append(new Option(item.customerName, item.id));
                            })

                            $("#customerInfo").val(orderInfo.customerId)
                            form.render('select');
                        }
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                }, 'GET');
            }else{
                $("#orderTime").val()
                $("#purchaseNameInfo").val()
                $("#purchaseCode").val()
                $("#orderType").val()
                $("#orderNo").val()
                $("#customerInfo").val()
                form.render('select');
            }
        });


        //表单提交事件
        form.on('submit(productOrderInfoFormSubmit)', function (d) {
            layer.load(2);
            d.field.customerId = $("#customerInfo").val();
            d.field.orderNo = $("#orderNoInfo").val();
            d.field.productDetailId = $("#inSkuCodeHave").val();
            admin.req('production/delivery/admin/orderDetailInfo/add', d.field, function (res) {
                layer.closeAll('loading');
                if (res.code == 200) {
                    layer.msg(res.msg, {icon: 1});
                    table.reload('proDeliveryOrderDetailTableInfo');
                    layer.closeAll('page');
                } else {
                    layer.msg(res.msg, {icon: 2});
                }
            }, 'POST');
            return false;
        });
    });
</script>